package ch.manage.movies.movieInfoFetcher;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.LinkedList;

import ch.manage.movies.movie.Movie;
import ch.manage.movies.ui.ErrorWindow;

import com.google.gson.Gson;

public class RTMovieInfoFetcher implements ImovieInfoFetcher {
	LinkedList<Movie> potentialMovies;
	Gson gson = new Gson();

	@Override
	public LinkedList<Movie> getMovieInfo(String movieName) {
		URL url = null;
		try {
			url = new URL("http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=7zzhnrzv3hpyaw2aqvxjvbbs&q="+ URLEncoder.encode(movieName, "UTF-8"));
			BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
			String inputLine = null;
			while (true) {
				System.out.println(in.readLine());
				inputLine = inputLine+""+in.readLine();
			}
//			System.out.println(inputLine);
//			in.close();
		} catch (Exception e) {
			ErrorWindow error = new ErrorWindow(e.getMessage());
			error.setVisible(true);
		}

		return null;
	}

	public static void main(String[] args) {
		RTMovieInfoFetcher rt = new RTMovieInfoFetcher();
		rt.getMovieInfo("Star Wars");
	}
}
